package com.tencent.liteav.demo;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;

import static com.tencent.liteav.demo.livepusher.camerapush.ui.view.PusherVideoQualityFragment.SP_KEY_VIDEO_IS_LOGO;
import static com.tencent.liteav.demo.livepusher.camerapush.ui.view.PusherVideoQualityFragment.SP_NAME;

/**
 * Created by Lesley on 2020-09-18.
 */
public class LivePushActivity extends Activity {

    private TextView tv_logo;
    private EditText et_room_name, et_room_url;
    private Switch switch_logo;
    private boolean isLogo = true;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_live_push);
        switch_logo = findViewById(R.id.switch_logo);
        et_room_name = findViewById(R.id.et_room_name);
        et_room_url = findViewById(R.id.et_room_url);
        tv_logo = findViewById(R.id.tv_logo);
        
        switch_logo.setChecked(getSharedPreferences(SP_NAME, Context.MODE_PRIVATE).getBoolean(SP_KEY_VIDEO_IS_LOGO, true));
        switch_logo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                isLogo = isChecked;
                tv_logo.setText("当前为" + (isChecked ? "开启" : "关闭") + "状态");
            }
        });

        findViewById(R.id.tv_save).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String roomName = et_room_name.getText().toString().trim();
                String roomUrl = et_room_url.getText().toString().trim();
                if (TextUtils.isEmpty(roomName)) {
                    ToastUtils.showShort("直播名称地址不能为空");
                    return;
                }
                if (TextUtils.isEmpty(roomUrl)) {
                    ToastUtils.showShort("直播地址不能为空");
                    return;
                }

                getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
                        .edit()
                        .putBoolean(SP_KEY_VIDEO_IS_LOGO, isLogo)
                        .apply();

                onBackPressed();
            }
        });
    }

}
